# Contributor: Jakob Meier <comcloudway@ccw.icu>
# Maintainer: Jakob Meier <comcloudway@ccw.icu>

pkgname=vlang
pkgver=0.4.8
# this has to be updated with the version
_vc_commit_sha="54beb1f416b404a06b894e6883a0e2368d80bc3e"
pkgrel=0
pkgdesc="Simple, fast, safe, compiled language for developing maintainable software."
url="https://vlang.io"
arch="x86_64 aarch64"
license="MIT"
# to be able to symlink /usr/lib/vlang/thirdparty/tcc/lib/libgc.a to /usr/lib/libgc.a
depends="gc-dev"
makedepends="gcc gc-dev libx11-dev"
source="
v-$pkgver.tar.gz::https://github.com/vlang/v/archive/refs/tags/$pkgver.tar.gz
vc-$pkgver.tar.gz::https://github.com/vlang/vc/archive/$_vc_commit_sha.tar.gz
"
builddir="$srcdir/v-$pkgver"
options="net"

build() {
	mv "../vc-$_vc_commit_sha" ./vc

	# cannot rely on prebuild tcc libgc.a
	# needs gc-dev
	mkdir -p thirdparty/tcc/lib
	ln -s /usr/lib/libgc.a thirdparty/tcc/lib/libgc.a

	gcc -std=gnu11 -w -o v1 vc/v.c -lm -lpthread
	./v1 -no-parallel -o v2 -prod cmd/v
	./v2 -o v -prod cmd/v
	rm -rf v1 v2

	./v run ./cmd/tools/detect_tcc.v

	VEXE=$builddir/v ./v build-tools -v
}

check() {
	./v self
}

package() {
	install -d $pkgdir/usr/lib/vlang $pkgdir/usr/share/vlang $pkgdir/usr/bin
	install -Dm644 LICENSE pkgdir/usr/share/licenses/$pkgname/LICENSE
	install -Dm755 v $pkgdir/usr/lib/vlang
	cp -a cmd $pkgdir/usr/lib/vlang/
	cp -a examples $pkgdir/usr/share/vlang/
	cp -a thirdparty $pkgdir/usr/lib/vlang/
	cp -a vlib $pkgdir/usr/lib/vlang/
	cp v.mod $pkgdir/usr/lib/vlang/
	ln -s /usr/lib/vlang/v $pkgdir/usr/bin/v

	touch $pkgdir/usr/lib/vlang/cmd/tools/.disable_autorecompilation
}
sha512sums="
b3c3b6660b08b8b63ceadf0a7a52710a3a86a8c30a20e71da6c21b15182be266a60080febc94357e6729995106717ac13ff709af74dd37f253ac8b67d4849538  v-0.4.8.tar.gz
0d9e75ccdb4845bcbc5bdea9846936914b7a80fe3ca17afbb661c23773a13e7469476e2096c010110ee5ef0e2a303bc8063d721b301db20ba5949fce0fddc6cc  vc-0.4.8.tar.gz
"
